package com.gitee.fsmxm.ocon.model;

import com.gitee.fsmxm.ocon.core.FileExtNotFoundException;
import com.gitee.fsmxm.ocon.util.IOUtils;

import java.io.File;
import java.util.Objects;

/**
 * 带有扩展名的文件
 *
 * @author fsmxm
 */
public class ExtFile {

    private File file;
    /**
     * 扩展名
     */
    private String ext;

    public ExtFile(File file) throws FileExtNotFoundException {
        final String ext = IOUtils.getExt(file.getName());
        if (ext == null) {
            throw new FileExtNotFoundException("file ext not found. file: " + file.getName());
        }
        this.file = file;
        this.ext = ext;
    }

    public ExtFile(File file, String ext) {
        this.file = file;
        this.ext = ext;
    }

    public File getFile() {
        return file;
    }

    public String getExt() {
        return ext;
    }

    @Override
    public String toString() {
        return "ExtFile{" +
                "file=" + file +
                ", ext='" + ext + '\'' +
                '}';
    }
}
